package com.woniuxy.producer;

import com.woniuxy.util.RabbitmqConst;
import org.checkerframework.checker.units.qual.C;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

/**
 * @author ：CuiYC
 * @description：
 * @date ：Created in 2025/3/20 16:05
 * @modified By：
 */
@Component
public class DelayProducer {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void send(String msg, String routeKey, Integer ttl){
        rabbitTemplate.convertAndSend(RabbitmqConst.DELAY_EXCHANGE, routeKey, msg,
                new MessagePostProcessor() {
                    @Override
                    public Message postProcessMessage(Message message) throws AmqpException {
                        message.getMessageProperties().setDelay(ttl);
                        return message;
                    }
                });
    }
}
